package api

import (
	"context"
	"github.com/cloudwego/hertz/pkg/app"
	"monthly/biz/handler/request"
	pb "monthly/kitex_gen/monthly/wallet"
	"monthly/utils"
)

var (
	WalletClient = utils.GetWalletClient()
)

func Recharge(ctx context.Context, c *app.RequestContext) {
	var req request.RechargeReq
	if err := c.Bind(&req); err != nil {
		c.JSON(200, map[string]interface{}{
			"code": 400,
			"msg":  "查询失败",
			"data": err.Error(),
		})
		return
	}
	recharge, _ := WalletClient.Recharge(ctx, &pb.RechargeReq{
		PId:              int16(req.PId),
		RechargeAmount:   req.RechargeAmount,
		RechargeChannels: req.RechargeChannels,
	})
	c.JSON(200, recharge)
}

func Withdrawal(ctx context.Context, c *app.RequestContext) {
	var req request.WithdrawalReq
	if err := c.Bind(&req); err != nil {
		c.JSON(200, map[string]interface{}{
			"code": 400,
			"msg":  "查询失败",
			"data": err.Error(),
		})
		return
	}
	withdrawal, _ := WalletClient.Withdrawal(ctx, &pb.WithdrawalReq{
		PId:                int16(req.PId),
		WithdrawalAmount:   req.WithdrawalAmount,
		WithdrawalChannels: req.WithdrawalChannels,
	})
	c.JSON(200, withdrawal)
}
